package tech.aistar.mapper.deamnd;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tech.aistar.vo.demand.DemandQueryVo;


import java.util.List;

/**
 * Created by 豆梦寒 on 2019/10/10.
 */
@Repository
public interface DemandQueryMapper {
    /**
     * 根据需求名称模糊查询
     */
    List<DemandQueryVo> findByName(String title);

    /**
     * 根据类别查询
     */
    @Select("select d.* ,u.name from demand d join user_info u on d.userinfo_id = u.id where d.category_id = #{value}")
    List<DemandQueryVo> findByCategory(Integer categoryId);

    /**
     * 根据详细类别查询
     */
    @Select("select d.* ,u.name from demand d join user_info u on d.userinfo_id = u.id where d.categorydetail_id = #{value}")
    List<DemandQueryVo> findByCategoryDetail(Integer categorydetailId);

    /**
     * 根据成交数降序排序
     */
    @Select("select d.* ,u.name from demand d join user_info u on d.userinfo_id = u.id order by d.count desc")
    List<DemandQueryVo> findByCount();

    /**
     * 根据发布时间降序排序
     */
    @Select("select d.* ,u.name from demand d join user_info u on d.userinfo_id = u.id order by d.begin_time desc")
    List<DemandQueryVo> findBybeginTime();

    /**
     * 根据价格降序排序
     */
    @Select("select d.* ,u.name from demand d join user_info u on d.userinfo_id = u.id order by d.price desc")
    List<DemandQueryVo> findByPriceDesc();

    /**
     * 根据价格升序排序
     */
    @Select("select d.* ,u.name from demand d join user_info u on d.userinfo_id = u.id order by d.price")
    List<DemandQueryVo> findByPrice();

    /**
     * 根据价格区间查询
     */
    List<DemandQueryVo> findByPriceRange(@Param("minPrice") Double minPrice, @Param("maxPrice") Double maxPrice);

    /**
     * 查询需求和用户昵称
     */
    @Select("select d.* ,u.name from demand d join user_info u on d.userinfo_id = u.id where d.end_time > now()")
    List<DemandQueryVo> findAndName();


}
